package lxxcbtdsz;

import java.util.HashSet;
import java.util.Set;

class Solution {
    public int[] numsSameConsecDiff(int n, int k) {

        Set<Integer> topNum = new HashSet();
        for (int i = 1; i <10 ; i++) {
            topNum.add(i);
        }

        for (int i = 0; i < k-1; i++) {
            Set<Integer> behindNum = new HashSet();
            for (int x : topNum) {
                int midNum = x%10;
                if (midNum+k<=9)
                    behindNum.add(x*10+(midNum+k));
                if (midNum-k>=0)
                    behindNum.add(x*10+(midNum-k));

            }
            topNum = behindNum;
        }

        if (n ==0)
            topNum.add(0);

        int[] nums = new int[topNum.size()];
        int index =0;
        for (int x :topNum) {
            nums[index++] = x;
        }
        return nums;
    }
}